package per.com.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import per.com.bean.BaseBean;
import per.com.bean.others.DeviceBean;
import per.com.dao.DeviceDao;

import javax.annotation.Resource;
import java.util.List;

@Controller
public class DeviceController {

    @Resource
    private DeviceDao deviceDao;

    @ResponseBody
    @RequestMapping("/getAll")
    public BaseBean<DeviceBean> getDevices(){
        return new BaseBean<DeviceBean>(0,"success",deviceDao.getAllDevices());
    }

    @RequestMapping("/userAdmin")
    public String userManager(){
        return "home";
    }

    @RequestMapping("/home")
    public String backHome(){
        return "first";
    }

    @RequestMapping("/setAdmin")
    public String setManager(){
        return "set";
    }

    @RequestMapping("/departManage")
    public String departManage(){
        return "departManage";
    }

    @RequestMapping("/teacherManage")
    public String teacherManage(){
        return "teachermanage";
    }



    @RequestMapping("/studentmanage")
    public  String studentmanage(){return "studentmanage";}

    @RequestMapping("/annomanage")
    public String annomanage(){return "sportsystem/sportConfig";}

    @RequestMapping("/attendence")
    public String attendence(){return "课堂点名";}

    @RequestMapping("/semesterTarget")
    public String semesterTarget(){return "semesterTarget";}

    @RequestMapping("/sportConfig")
    public String sportConfig(){return "sportsystem/sportConfig";}

    @RequestMapping("/scoreManage")
    public String scoreManage(){return "scoreManage";}

    @RequestMapping("/runManage")
    public String runManage(){return "runManage";}

    @RequestMapping("/cheatManage")
    public String cheatManage(){return "cheatManage";}

    @RequestMapping("/scoreImport")
    public String scoreImport(){return "scoreImport";}

    @RequestMapping("/history")
    public String history(){return "history";}

    @RequestMapping("/test_scoreManage")
    public String test_scoreManage(){return "test_scoreManage";}

    @RequestMapping("/venueManage")
    public String venueManage(){return "venueManage";}

    @RequestMapping("/userManage")
    public String userManage(){return "userManage";}

    @RequestMapping("/attendanceManage")
    public String attendanceManage(){return "attendanceManage";}

    @RequestMapping("/setAttendance")
    public String setAttendance(){return "setAttendance";}

    @RequestMapping("/outInVenueManage")
    public String outInVenueManage(){return "outInVenueManage";}

    @RequestMapping("/orderManage")
    public String orderManage(){return "orderManage";}

    @RequestMapping("/newAnno")
    public String newAnno(){return "newAnno";}

    @ResponseBody
    @RequestMapping("/q1")
    public List<DeviceBean> qd(){
        return deviceDao.getAllDevices();
    }

    @RequestMapping("/addset")
    public String addset(){
        return "addset";
    }

    @RequestMapping(value = "/saveDevice")
    @ResponseBody
    public BaseBean save(@RequestParam("dname")String dname,@RequestParam("connectType")String connectType){
        DeviceBean deviceBean = new DeviceBean();
        deviceBean.setDname(dname);
        deviceBean.setConnectType(connectType);
        deviceBean.setDeviceCate(99);
        try{
            deviceDao.save(deviceBean);
            return new BaseBean(0,"添加成功");
        }catch (Exception e){
            return new BaseBean(11,"添加失败");
        }
    }

}
